package cn.holy.app.xcddt.database.dao;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;

import java.util.List;

import cn.holy.app.xcddt.domain.RecordGroup;

import static androidx.room.OnConflictStrategy.REPLACE;

/**
 * Created by 69568 on 2018/2/27.
 */
@Dao
public interface RecordGroupDao {

    @Insert(onConflict = REPLACE)
    void save(RecordGroup recordGroup);


    @Query("SELECT * FROM record_groups as groups where user_id = :user_id order by record_num  desc ")
    LiveData<List<RecordGroup>> queryAll(int user_id);

    @Query("select count(*) from record_groups where user_id = :user_id")
    Integer countGroups(int user_id);

    @Query("select * from record_groups  where user_id = :user_id order by id  desc limit 1")
    RecordGroup lastGroup(int user_id);


    @Query("select * from record_groups where id = :record_num order by id desc limit 1 ")
    RecordGroup loadGroup(int record_num);
}
